package com.example.util;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;

import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

public class T {
    private static final String SPE_FLAG = ":";
    private static final String NULL = " ";

    public static void main(String[] args) throws IOException {
        String path = "E:\\JavaSpace\\java_training_ground\\" + "edit-yml\\src\\main\\resources\\application.yml";
        File file = new File(path);
        // InputStream in = new BufferedInputStream(new FileInputStream(file));
        List<String> list = FileUtil.readLines(file, Charset.defaultCharset());
        ArrayList<String> list2 = new ArrayList<>();
        list.forEach(e -> {
            if (e.trim().contains("active")) {
                List<String> list1 = StrUtil.split(e, SPE_FLAG);
                e = list1.get(0) + SPE_FLAG + NULL + "prod";
            }
            list2.add(e);
            System.out.println(e);
        });

        boolean del = FileUtil.del(path);
        System.out.println("del = " + del);

        FileUtil.writeLines(list2, path, Charset.defaultCharset()).createNewFile();
    }
}
